//
//  CYBTableViewCell.m
//  01-基本框架搭建
//
//  Created by apple on 16/8/30.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "CYBTableViewCell.h"
#import "CYBStatus.h"
#import "CYBStatusSwitch.h"
#import "CYBStatusArrows.h"
#import "CYBScorePushController.h"
#import "CYBStatusLabel.h"


@interface CYBTableViewCell ()

/**
 *  定义向右箭头imageView
 */
@property (nonatomic, strong) UIImageView *arrowsView;

/**
 *  定义开关按钮
 */
@property (nonatomic, strong) UISwitch *switchView;


/**
 *  定义cell 的标签
 */
@property (nonatomic, strong) UILabel *labelView;

@end

@implementation CYBTableViewCell

//给控件添加get方法，就是为了不频烦的抢建控件，而使用赖加载的方法，使控件用的时候再创建，而且只创建一次
- (UIImageView *)arrowsView{
    if (_arrowsView == nil) {
        _arrowsView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow_right"]];
    }
    return _arrowsView;
}
//开关赖加载方法
- (UISwitch *)switchView{
    if (_switchView == nil) {
        _switchView = [[UISwitch alloc] init];
    }
    return _switchView;
}

//标签赖加载
- (UILabel *)labelView{

    if (_labelView == nil) {
        _labelView = [[UILabel alloc] init];
        _labelView.bounds = CGRectMake(0, 0, 100, 30);
        _labelView.backgroundColor = [UIColor redColor];
    }
    return _labelView;
}


- (void)setStatus:(CYBStatus *)Status{

    _Status = Status;

    if (self.Status.icon) { //如果有图片时才执行里面代码
     
         self.imageView.image = [UIImage imageNamed:Status.icon];
    }
  
    self.textLabel.text = Status.title;
    
    if ([Status isKindOfClass:[CYBStatusArrows class]]) {
        
        self.accessoryView = self.arrowsView;
        
    }else if ([Status isKindOfClass:[CYBStatusSwitch class]]){
    
        self.accessoryView = self.switchView;
        self.selectionStyle = UITableViewCellSelectionStyleNone;    //设置cell选中时的状态 无
        
    }else if ([Status isKindOfClass:[CYBStatusLabel class]]){
        
        self.accessoryView = self.labelView;
        self.selectionStyle = UITableViewCellSelectionStyleNone;    //设置cell选中时的状态 无
        
    }else{
    
        self.accessoryView = nil;
        self.selectionStyle = UITableViewCellSelectionStyleNone;    //设置cell选中时的状态 无
    }
    

}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
    }
    return self;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    
    static NSString *ID = @"cell";
        CYBTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (cell == nil) {
            cell = [[CYBTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        }
  
    return cell;

}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
